class solution():
    def solvesudoku(self,board):
        self.helper(board,0)
    def helper(self,board,index):
        if index>=81:
            self.printsolution(board)
            return
        if board[index]==0:
            for i in range(1,10):
                if self.isValid(board,index,i):
                    board[index]=i#填入数字
                    self.helper(board,index+1)
                    board[index]=0#若不满足条件，恢复原0值，防止影响之后数字的填写
        else:#如果当前格有已知数，跳出此格
            self.helper(board,index+1)
    def printsolution(self,board):
        for i in range(0,81,9):
            print(board[i:i+9])#注意输出格式
    def isValid(self,board,index,num):
        row=index//9#当前格子行数
        column=index%9#当前格子列数
        for i in range(index+9,81,9):#检查和同列（下方）的格子是否合理
            if board[i]==num:
                return False
        for i in range(index-9,-1,-9):#检查和同列（上方）的格子是否合理
            if board[i]==num:
                return False
        for i in range(row*9,(row+1)*9):#检查和同行的格子是否矛盾
            if board[i]==num:
                return False
        for i in range(row-row%3,3+row-row%3):#检查和同粗线的格子是否有矛盾
            for j in range(column-column%3,3+column-column%3):
                if board[i*9+j]==num:
                    return False
        return True
board=[4,1,0,0,0,7,8,5,0,
       8,0,6,0,0,0,0,0,9,
       0,2,0,0,9,0,6,0,0,
       0,0,4,0,0,0,0,1,2,
       2,0,0,5,8,0,0,7,0,
       0,0,0,0,0,0,5,0,0,
       0,0,0,7,0,2,0,0,0,
       0,0,8,0,1,0,0,0,0,
       0,7,0,0,6,0,0,0,0]
solution().solvesudoku(board)